﻿Imports System.Windows.Forms
Imports DirectShowLib
Imports System.Runtime.InteropServices
Imports System.Threading
Imports System.Drawing.Imaging
Imports UCBase
Imports System.Drawing

Public Class ImageSourceB
    Implements I_ImageExchange
    Implements UCBase.I_LoadSave
    Private BackPic As New BackgroundCreator
    Private Mov As New Mover
    Private m_OutPic As Bitmap
    Public Event ImageReady(ByVal Image As System.Drawing.Bitmap) Implements UCBase.I_ImageExchange.ImageOut1

    Public Function GetSettings() As String Implements UCBase.I_LoadSave.GetSettings
        Return OpenFileDialog1.FileName
    End Function

    Public Sub SetSettings(ByVal Settings As String) Implements UCBase.I_LoadSave.SetSettings
        PictureBox1.Image = Bitmap.FromFile(Settings)
        Timer1.Enabled = True
    End Sub
    Private Sub Button3D1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3D1.Click
        If OpenFileDialog1.ShowDialog = DialogResult.OK Then
            PictureBox1.Image = Bitmap.FromFile(OpenFileDialog1.FileName)
            Timer1.Enabled = True
        End If
    End Sub

    Private Sub ImageSource_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.BackgroundImage = BackPic.CreatePic(Me.Width, Me.Height)
        Mov.Connect(Me)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If m_OutPic IsNot Nothing Then
            m_OutPic.Dispose()
        End If
        m_OutPic = New Bitmap(PictureBox1.Image)
        RaiseEvent ImageReady(m_OutPic)

    End Sub

    Private Sub ImageSource_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        '370, 238
        Me.Width = 370
        Me.Height = 240

    End Sub

    Private Sub Button3D5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3D5.Click
        Timer1.Enabled = True
    End Sub
End Class
